/******************** 
	作用:是传图片配置
	作者:蔡俊雄
	版本:V1.0
	时间:2015-08-21
********************/

$(function() {
	//-----------------上传图片设置-----------------
	//编辑器设置
	var uploadEditor = KindEditor.editor({
//		uploadJson : '/Foundation/ImageTextReply?isUpfile=1',
		uploadJson : '/shop/admin/config/general?action=uploadImg',
//		fileManagerJson : '/file/list',
		allowFileManager: false,
	});
	//显示图片上传对话框
	function showImageUploadDialog(imageId, hiddenId) {
		uploadEditor.loadPlugin('image', function() {
			uploadEditor.plugin.imageDialog({
                            showRemote:false,
				imageUrl: $(hiddenId).val(),
				clickFn: function(url, title, width, height, border, align) {
					$(hiddenId).val(url);
					$(imageId).attr("src", url);
					uploadEditor.hideDialog();
				}
			});
		});
	}

	function initImageUploadDialog(btnId, imageId, hiddenId) {
		$(btnId).on("click", function(e) {
			showImageUploadDialog(imageId, hiddenId);
		});
	}

	function initImageUploadShareDialog(btnId, imageId, hiddenId) {
		$(btnId).on("click", function(e) {
			showImageUploadDialog(imageId, hiddenId);
		});
	}
	
	$("#shopLogo").blur(function() {
		var url=$("#shopLogo").val();
		if(url)
			$("#previewImage").attr("src", url);
	});
	$("#sharePic").blur(function() {
		var url=$("#sharePic").val();
		if(url)
			$("#previewShareImage").attr("src", url);
	});

	initImageUploadDialog("#upload,#previewImage", "#previewImage", "#shopLogo");
	initImageUploadShareDialog("#uploadSharePic,#previewShareImage", "#previewShareImage", "#sharePic");
	
	
	
	//-----------------退换货周期-----------------
	$("input[name=isEnableReturn]").on("click", function(e) {
		var index=$("input[name=isEnableReturn]").index($(this));
		if(index==0){
			$("#periodContainer").removeClass("hide");
		}else{
			$("#periodContainer").addClass("hide");
		}
	});
	$("input[name=concerned]").on("click", function(e) {
		var value = $(this).attr("data-value");
		if(value=="2"){
			$("#extraConainer").removeClass("hide");
		}else{
			$("#extraConainer").addClass("hide");
		}
	});
	
});